package main

import (
	"fmt"
	"code.google.com/p/odie"
)

func helloHandler(w *odie.ResponseWriter, req *odie.Request, vars odie.Context) {

	name := vars.Get("name")

	if name == "" {
		name = req.Context.Get("name")
	}

	if name == "" {
		fmt.Fprintf(w, "Hi! What's your name?")
		w.Prompt("name")
	} else {
		w.AddContext("name", name)
		fmt.Fprintf(w, "Hello, %s! How can I help you?", name)
	}
}


func whatHandler(w *odie.ResponseWriter, req *odie.Request, vars odie.Context) {

	name := req.Context.Get("name")

	if name == "" {
		fmt.Fprintf(w, "I don't know your name.")
		w.Prompt("name")
	} else {
		fmt.Fprintf(w, "Your name is %s.", name)
	}
}

func init () {

	odie.Handle("hello", helloHandler) 
	odie.Handle("my name is $name", helloHandler) 
	odie.Handle("what is my name", whatHandler)
}

                
